package com.bjsxt.reflex;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class TestSetAccessable {
    public static void main(String[] args) throws Exception {
        Users u = new Users();
        Class clazz = u.getClass();
        Field field=clazz.getDeclaredField("username");
        //忽略安全检查
        field.setAccessible(true);
        field.set(u,"oldlu");
        Object object  =field.get(u);
        System.out.println(object);
        System.out.println("---------------");
        Method method = clazz.getDeclaredMethod("suibian");
        method.setAccessible(true);
        method.invoke(u);
    }
}
